<template>
  <div class="container">
    <div class="top-bar">
      <div class="left">
        客服电话更改
      </div>
      <el-button @click="save" size="small" type="primary">
        保存
      </el-button>
    </div>
    <el-form ref="settingForm" :model="form">
      <el-form-item
        :rules="{
          required: true,
          message: '请填写客服电话',
          trigger: 'blur'
        }"
        prop="service_tel"
        label="客服电话"
      >
        <el-input style="width:200px;" v-model="form.service_tel"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getPageSetting, setPageSetting } from "@/api/user";
export default {
  data() {
    return {
      form: {
        service_tel: null
      }
    };
  },
  computed: {},

  watch: {},

  methods: {
    save() {
      this.$refs.settingForm.validate(valid => {
        if (valid) {
          setPageSetting({
            service_tel: this.form.service_tel
          }).then(res => {
            if (res.code === 200) {
              this.$message({
                message: "保存成功",
                type: "success"
              });
            }
          });
        } else {
          return false;
        }
      });
    }
  },

  created() {
    getPageSetting().then(res => {
      if (res.code === 200) {
        this.form.service_tel = res.data.service_tel;
      }
    });
  },

  components: {}
};
</script>
<style lang="scss" scoped>
.container {
  .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #dfdfdf;
    padding-bottom: 10px;
  }
}
</style>
